﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AiXiu.Model;
using AiXiu.BLL;

namespace AiXiu.WebSite
{
    public partial class MyInfo : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //第一次加载页面
            if (!IsPostBack)
            {
                //读取用户资料
                TBUsers users = IdentityManager.ReadUser();

                lbName.Text = users.NickName;
                lbBirthday.Text = users.Birthday.HasValue ? users.Birthday.Value.ToString("yyyy-MM-dd") : "";
                lbAddress.Text = users.Address;
                lbHobby.Text = users.Hobby;
                //判断当前用户头像是否为空，若为空，给一个默认头像，否则以数据库中的数据为准
                if (string.IsNullOrEmpty(users.Avatar))
                {
                    avatar.ImageUrl = "~/imgs/avatar.jpg";
                }
                else
                {
                    avatar.ImageUrl = users.Avatar;
                }
            }
        }
        /// <summary>
        /// 退出登录，清除用户缓存，跳转到登录页面
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnExitLogin_Click(object sender, EventArgs e)
        {
            System.Web.Security.FormsAuthentication.SignOut();
            Response.Redirect("Login.aspx");
        }
    }
}